package com.sky.controller.user;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.sky.controller.admin.ShopController.SHOP_STATUS;

@RestController
@RequestMapping("/user/shop")
@Slf4j
@Api(tags = "用户获取店铺营业状态接口")
public class UserShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 用户获取店铺营业状态
     * @return
     */
    @ApiOperation(value = "用户获取店铺营业状态")
    @GetMapping("/status")
    public Result<Integer> getShopStatus() {
        // 读取redis营业状态
        Integer status = (Integer) redisTemplate.opsForValue().get(SHOP_STATUS);

        if (status == null) {
            // 首次进入页面 手动获取状态
            redisTemplate.opsForValue().set(SHOP_STATUS, 1);
            status = 1;
        }
        return Result.success(status);
    }
}
